//
//  PPImageShowViewNine.m
//  PetParadise
//
//  Created by 陈无忌 on 8/4/14.
//  Copyright (c) 2014 whalefin. All rights reserved.
//

#import "PPImageShowViewNine.h"
#import "supportingHeadFiles.h"

@implementation PPImageShowViewNine

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

+(CGFloat)getViewHeight:(NSArray <PPTopicImage,Optional>*)image
{
    int count = image.count;
    if (count == 0) {
        return 0;
    }else if (count > 0 && count <= 3){
        return 75;
    }else if (count > 3 && count <= 6){
        return 155;
    }else{
        return 235;
    }
}

+(PPImageShowViewNine *)setImageWithImage:(NSArray <PPTopicImage,Optional>*)image andView:(PPImageShowViewNine *)view
{
    for (UIImageView *subView in view.subviews)
    {
        [subView removeFromSuperview];
    }
    int count = image.count;
    NSMutableArray *pathArray = [[NSMutableArray alloc] init];
    if (count > 0) {
        for (PPTopicImage *img in image) {
            if (!img.img) {
                img.img = @"";
            }
            [pathArray addObject:img.img];
        }
        view.hidden = NO;
    }
    if (count == 0) {
        view.hidden = YES;
        //
    }else if (count == 1){
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 75, 75)];
        [imageView setImageWithURL:[PPImageUrl getImageUrl:pathArray.firstObject] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        [imageView setContentMode:UIViewContentModeScaleAspectFill];
        [imageView setClipsToBounds:YES];
        [view addSubview:imageView];
    }else if(count == 2){
        for (int i = 0; i < count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            switch (i) {
                case 0:
                    imageView.frame = CGRectMake(0, 0, 75, 75);
                    break;
                case 1:
                    imageView.frame = CGRectMake(80, 0, 75, 75);
                    break;
                default:
                    break;
            }
            [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            [imageView setClipsToBounds:YES];
            [view addSubview:imageView];
        }
    }else if (count == 3){
        for (int i = 0; i < count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            switch (i) {
                case 0:
                    imageView.frame = CGRectMake(0, 0, 75, 75);
                    break;
                case 1:
                    imageView.frame = CGRectMake(80, 0, 75, 75);
                    break;
                case 2:
                    imageView.frame = CGRectMake(160, 0, 75, 75);
                    break;
                default:
                    break;
            }
            [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            [imageView setClipsToBounds:YES];
            [view addSubview:imageView];
        }
    }else if (count == 4){
        for (int i = 0; i < count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            switch (i) {
                case 0:
                    imageView.frame = CGRectMake(0, 0, 75, 75);
                    break;
                case 1:
                    imageView.frame = CGRectMake(80, 0, 75, 75);
                    break;
                case 2:
                    imageView.frame = CGRectMake(160, 0, 75, 75);
                    break;
                case 3:
                    imageView.frame = CGRectMake(0, 80, 75, 75);
                    break;
                default:
                    break;
            }
            [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            [imageView setClipsToBounds:YES];
            [view addSubview:imageView];
        }
    }else if (count == 5){
        for (int i = 0; i < count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            switch (i) {
                case 0:
                    imageView.frame = CGRectMake(0, 0, 75, 75);
                    break;
                case 1:
                    imageView.frame = CGRectMake(80, 0, 75, 75);
                    break;
                case 2:
                    imageView.frame = CGRectMake(160, 0, 75, 75);
                    break;
                case 3:
                    imageView.frame = CGRectMake(0, 80, 75, 75);
                    break;
                case 4:
                    imageView.frame = CGRectMake(80, 80, 75, 75);
                    break;
                default:
                    break;
            }
            [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            [imageView setClipsToBounds:YES];
            [view addSubview:imageView];
        }
    }else if (count == 6){
        for (int i = 0; i < count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            switch (i) {
                case 0:
                    imageView.frame = CGRectMake(0, 0, 75, 75);
                    break;
                case 1:
                    imageView.frame = CGRectMake(80, 0, 75, 75);
                    break;
                case 2:
                    imageView.frame = CGRectMake(160, 0, 75, 75);
                    break;
                case 3:
                    imageView.frame = CGRectMake(0, 80, 75, 75);
                    break;
                case 4:
                    imageView.frame = CGRectMake(80, 80, 75, 75);
                    break;
                case 5:
                    imageView.frame = CGRectMake(160, 80, 75, 75);
                    break;
                default:
                    break;
            }
            [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            [imageView setClipsToBounds:YES];
            [view addSubview:imageView];
        }
    }else if (count == 7){
        for (int i = 0; i < count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            switch (i) {
                case 0:
                    imageView.frame = CGRectMake(0, 0, 75, 75);
                    break;
                case 1:
                    imageView.frame = CGRectMake(80, 0, 75, 75);
                    break;
                case 2:
                    imageView.frame = CGRectMake(160, 0, 75, 75);
                    break;
                case 3:
                    imageView.frame = CGRectMake(0, 80, 75, 75);
                    break;
                case 4:
                    imageView.frame = CGRectMake(80, 80, 75, 75);
                    break;
                case 5:
                    imageView.frame = CGRectMake(160, 80, 75, 75);
                    break;
                case 6:
                    imageView.frame = CGRectMake(0, 160, 75, 75);
                    break;
                default:
                    break;
            }
            [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            [imageView setClipsToBounds:YES];
            [view addSubview:imageView];
        }
    }else if (count == 8){
        for (int i = 0; i < count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            switch (i) {
                case 0:
                    imageView.frame = CGRectMake(0, 0, 75, 75);
                    break;
                case 1:
                    imageView.frame = CGRectMake(80, 0, 75, 75);
                    break;
                case 2:
                    imageView.frame = CGRectMake(160, 0, 75, 75);
                    break;
                case 3:
                    imageView.frame = CGRectMake(0, 80, 75, 75);
                    break;
                case 4:
                    imageView.frame = CGRectMake(80, 80, 75, 75);
                    break;
                case 5:
                    imageView.frame = CGRectMake(160, 80, 75, 75);
                    break;
                case 6:
                    imageView.frame = CGRectMake(0, 160, 75, 75);
                    break;
                case 7:
                    imageView.frame = CGRectMake(80, 160, 75, 75);
                    break;
                default:
                    break;
            }
            [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            [imageView setClipsToBounds:YES];
            [view addSubview:imageView];
        }
    }else{
        for (int i = 0; i < count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            switch (i) {
                case 0:
                    imageView.frame = CGRectMake(0, 0, 75, 75);
                    break;
                case 1:
                    imageView.frame = CGRectMake(80, 0, 75, 75);
                    break;
                case 2:
                    imageView.frame = CGRectMake(160, 0, 75, 75);
                    break;
                case 3:
                    imageView.frame = CGRectMake(0, 80, 75, 75);
                    break;
                case 4:
                    imageView.frame = CGRectMake(80, 80, 75, 75);
                    break;
                case 5:
                    imageView.frame = CGRectMake(160, 80, 75, 75);
                    break;
                case 6:
                    imageView.frame = CGRectMake(0, 160, 75, 75);
                    break;
                case 7:
                    imageView.frame = CGRectMake(80, 160, 75, 75);
                    break;
                case 8:
                    imageView.frame = CGRectMake(160, 160, 75, 75);
                    break;
                default:
                    break;
            }
            [imageView setImageWithURL:[PPImageUrl getImageUrl:[pathArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"defaultImage"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [imageView setContentMode:UIViewContentModeScaleAspectFill];
            [imageView setClipsToBounds:YES];
            [view addSubview:imageView];
        }
    }

    return view;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
